package com.inxedu.os.edu.service.course.impl;

import com.inxedu.os.edu.dao.EduRecommondCourseMapper;
import com.inxedu.os.edu.pojo.EduWebsiteCourse;
import com.inxedu.os.edu.pojo.EduWebsiteCourseDetail;
import com.inxedu.os.edu.pojo.EduWebsiteCourseDetailsss;
import com.inxedu.os.edu.pojo.WebCourseRecommond;
import com.inxedu.os.edu.service.course.RecommondCourse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class RecommondCourseImpl implements RecommondCourse {
    @Autowired
    private EduRecommondCourseMapper eduRecommondCourseMapper;

    @Override
    public List<EduWebsiteCourse> selectRecommond(EduWebsiteCourse eduWebsiteCourse) {
       /* EduWebsiteCourse edu=new EduWebsiteCourse();*/
        List<EduWebsiteCourse> eduWebsiteCourses = eduRecommondCourseMapper.selectRecommondList(eduWebsiteCourse);
        return eduWebsiteCourses;
    }

    @Override
    public int deleteCourse(Long id) {

        return eduRecommondCourseMapper.deleteCourse(id);
    }

    @Override
    public int updateSort(Long id,Long ordelNum) {

        return  eduRecommondCourseMapper.updateSort(id,ordelNum);
    }

    @Override
    public List<EduWebsiteCourse> findWebsiteCourse() {

        List<EduWebsiteCourse> eduWebsiteCourseList=eduRecommondCourseMapper.selectWebsiteCourse();

        return eduWebsiteCourseList;
    }



    //查询专业
    @Override
    public List<WebCourseRecommond> findWebCourseRecommond(WebCourseRecommond web) {

        List<WebCourseRecommond> webCourseRecommond = eduRecommondCourseMapper.findWebCourseRecommond(web);

        return webCourseRecommond;
    }
    //查询推荐分类
    @Override
    public List<EduWebsiteCourse> findrecommondCourse() {
        List<EduWebsiteCourse> findrecommond=eduRecommondCourseMapper.findrecommondCourse();

        return findrecommond;
    }

    //添加推荐课程
    @Override
    public int addrecommendCourse(String courseIds, Integer recommendId) {


        if(courseIds!=null && courseIds.trim().length()>0){
            if(courseIds.trim().endsWith(",")){
                courseIds = courseIds.trim().substring(1,courseIds.trim().length()-1);
            }
        }
        String[] split = courseIds.split(",");
        List<Integer> list=new ArrayList();
        for (int i=0;i<split.length;i++){
            list.add(Integer.parseInt(split[i]));
        }
        List<EduWebsiteCourseDetail> E=new ArrayList<>();
        for (int j=0;j<list.size();j++) {
            EduWebsiteCourseDetail eduWebsiteCourseDetail=new EduWebsiteCourseDetail();
            eduWebsiteCourseDetail.setRecommendId(recommendId);
            eduWebsiteCourseDetail.setCourseId(list.get(j));
            E.add(eduWebsiteCourseDetail);
        }


        int i=eduRecommondCourseMapper.addrecommendCourse(E);

        System.out.println(i);
        return i;
    }
}
